package com.syni.mdd.sjb.common.datatreaure.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.entity.DxshAppUserView;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.mapper.DxshAppUserViewMapper;
import com.syni.mdd.sjb.common.component.utils.common.utils.BeanUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.DateTimeUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.common.component.utils.common.utils.RpcResponseVo;
import com.syni.mdd.sjb.common.component.utils.feign.dto.mddUser.apiUser.GetMidongdongUserDto;
import com.syni.mdd.sjb.common.component.utils.feign.service.mdd.commonuser.UserRestService;
import com.syni.mdd.sjb.common.datatreaure.service.DxshAppUserViewService;
import com.syni.mdd.sjb.common.datatreaure.constants.ResultMsg;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.services.ViewRecordRqVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 服务案例阅读记录 服务实现类
 * </p>
 *
 * @author hwq
 * @since 2020-08-05
 */
@Service
public class DxshAppUserViewServiceImpl extends ServiceImpl<DxshAppUserViewMapper, DxshAppUserView> implements DxshAppUserViewService {

    @Autowired
    DxshAppUserViewService dxshAppUserViewService;
    @Autowired
    UserRestService userRestService;

    @Override
    public Map<String, Object> userViewRecord(ViewRecordRqVo viewRecordRqVo) {
        DxshAppUserView dxshAppUserView = new DxshAppUserView();
        GetMidongdongUserDto getMidongdongUserDto = new GetMidongdongUserDto();
        getMidongdongUserDto.setUserId(viewRecordRqVo.getUserId());
        RpcResponseVo rpcResponseVo = userRestService.getMidongdongUser(getMidongdongUserDto);
        if(rpcResponseVo.isSuccess()) {
            getMidongdongUserDto = rpcResponseVo.parseObject(GetMidongdongUserDto.class);
            dxshAppUserView.setPhone(getMidongdongUserDto.getPhone());
        }
        BeanUtils.copyProperties(viewRecordRqVo,dxshAppUserView);
        dxshAppUserView.setNewTime(DateTimeUtils.converDateToLocalDateTime(new Date()));
        dxshAppUserViewService.saveOrUpdate(dxshAppUserView);
        return ResultMapHelper.success(null, ResultMsg.HAND_SUCCESS);
    }
}
